<template>
    <div>
        <h2>{{item.title}}</h2>
        <div>
            <span>{{item.username}}</span>
            <span>{{item.time}}</span>
        </div>
        <button @click="goAdd(item.id)">编辑</button>
        <button @click="del(item.id)">删除</button>
    </div>
</template>

<script>
import request from '../util/request'
export default {
    props:['item'],
    created(){
        console.log(this);
    },
    methods:{
        del(id){
            request.delete('/api/del',{id}).then(res => {
                console.log("删除成功")
                this.$emit('getList');
            })
        },
        //编辑
        goAdd(id){
            // console.log(this.$router);
            // this.$router.push({path:'add',query:{id}})
            //本地存储
            localStorage.setItem('item',JSON.stringify(this.item));
            this.$router.push('/add');
        }
    }
}
</script>
